home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / wpfix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-22  |  2.4 KB  |  122 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. long inputlines = 0, outputlines = 0;
  6. long totallines = 0;
  7. char buffer[256];
  8. FILE *fp;
  9.  
  10. struct entry    {
  11.     char  *call;
  12. };
  13. struct entry far *e;
  14.  
  15.  
  16. int
  17. finddup (filenm, index)
  18. char *filenm;
  19. int index;
  20. {
  21. int retval = 0;
  22. long k;
  23. char *cp;
  24.  
  25.     if (buffer[0] < 'A')
  26.         return 1;
  27.     putchar ('\r');
  28.     clreol();
  29.     printf ("%s processing #%05ld/%05ld: '%s'....", filenm, inputlines, outputlines, buffer);
  30.     for (k = index + 1; k < totallines; k++)    {
  31.         if (!strncmp (buffer, e[k].call, 6))    {
  32.             retval = 1;
  33.             break;
  34.         }
  35.     }
  36.     return (retval);
  37. }
  38.  
  39.  
  40. void
  41. process (filenm, maxlen)
  42. char *filenm;
  43. int maxlen;
  44. {
  45. register FILE *out, *fpin;
  46. register char *sptr = buffer;
  47. register char *cp, *cp2;
  48. int llen;
  49. long k;
  50.  
  51.     inputlines = outputlines = 0;
  52.     if ((fpin = fp = fopen (filenm, "r")) == NULL)
  53.         return;
  54.     if ((out = fopen ("spool/temp", "w")) == NULL)    {
  55.         fclose (fp);
  56.         return;
  57.     }
  58.     while (!feof(fpin))    {
  59.         fgets (sptr, 256, fpin);
  60.         if (feof(fpin))
  61.             break;
  62.         totallines++;
  63.     }
  64.     rewind(fpin);
  65.     printf ("File '%s' originally contains %ld entries\n", filenm, totallines);
  66.     e = malloc (totallines * sizeof (char *));
  67.     if (e == 0)    {
  68.         printf ("Error allocating memory\n");
  69.         exit (0);
  70.     }
  71.     for (k = 0; k < totallines; k++)    {
  72.         fgets (sptr, 256, fpin);
  73.         e[k].call = malloc(6);
  74.         strncpy (e[k].call, sptr, 6);
  75.     }
  76.     rewind(fpin);
  77.         
  78.     cp2 = strrchr (filenm, '/');
  79.     cp2++;
  80.     k = 0;
  81.     while (!feof(fpin))    {
  82.         fgets (sptr, 256, fpin);
  83.         if (feof(fpin))
  84.             break;
  85.         inputlines++;
  86.         llen = strlen(sptr);
  87.         if ((llen > maxlen+2) || (llen < maxlen))    {
  88.             k++;
  89.             continue;
  90.         }
  91.         cp = strchr (sptr, ' ');
  92.         *cp++ = 0;
  93.         if (!finddup (cp2, k))    {
  94.             while (*cp == ' ')
  95.                 cp++;
  96.             cp[strlen(cp) - 1] = 0;
  97.             fprintf(out,"%-*s %-14s\n", maxlen - 15, sptr, cp);
  98.             outputlines++;
  99.         }
  100.         k++;
  101.     }
  102.     fclose (fp);
  103.     fclose (out);
  104.     for (k = 0; k < totallines; k++)
  105.         free (e[k].call);
  106.     free (e);
  107.     unlink (filenm);
  108.     rename ("spool/temp", filenm);
  109.     printf ("\n\nFile '%s' complete!\nOriginal number of lines: %ld\nNew number of lines: %ld\nNumber of duplicate lines: %ld\n\n", filenm, inputlines, outputlines, inputlines - outputlines);
  110. }
  111.  
  112.  
  113. void
  114. main ()
  115. {
  116.     printf ("Quick hack to fix white pages duplicates\nStand by, this will take a while...\n\n");
  117. //    process ("spool/wpages", 28);
  118.     process ("spool/wpagebbs", 47);
  119. }
  120.  
  121.  
  122.